<?php
/**
 * @author       admin
 */
class Dispatcher {
    
    /**
     * @return   void
     */
    public function dispatch() {
        $webroot = preg_replace('#/[^/]+$#', '', $_SERVER['SCRIPT_NAME']);
        $router = Router::getInstance();
        $str_q	= isset($_GET['q'])?$_GET['q']:'';
        $str_q	= str_replace('-', '/', $str_q);
        $str_q	= str_replace(MY_FIX, '', $str_q);
        $params = $router->parse($str_q);
        
        $request = Request::getInstance();
        $request->setParams($params);
        $request->setParams($webroot, 'webroot');
        
        $module_class = $params['module'].'Action';
        if (!class_exists($module_class)) {
            Request::getInstance()->render404();
        }
        $module = new $module_class;
        
        $module->setParams($params);
        $module->setParamter($str_q);
        $module->setView(new PhpView());
        $module->getView()->webroot = $webroot;
        
        $module->execute();
    }
}
